<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="12">
            <a-form-model-item label="数据日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="dataDt">
              <j-date placeholder="请选择数据日期" v-model="model.dataDt"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="科目代码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="subjectNo">
              <a-input v-model="model.subjectNo" placeholder="请输入科目代码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="科目名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="subjectName">
              <a-input v-model="model.subjectName" placeholder="请输入科目名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="客户名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="khmc">
              <a-input v-model="model.khmc" placeholder="请输入客户名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="客户代码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="khdm">
              <a-input v-model="model.khdm" placeholder="请输入客户代码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="金融机构代码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="jrjgdm">
              <a-input v-model="model.jrjgdm" placeholder="请输入金融机构代码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="内部机构号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="nbjgh">
              <a-input v-model="model.nbjgh" placeholder="请输入内部机构号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="交易对手代码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="jydsdm">
              <a-input v-model="model.jydsdm" placeholder="请输入交易对手代码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="交易对手代码类别" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="jydsdmlb">
              <j-tree-select
                ref="treeSelect"
                placeholder="请选择交易对手代码类别"
                v-model="model.jydsdmlb"
                dict="llbb_param_config,name,code"
                pidValue="1490948870623547394"
                hasChildField="has_child"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="合同编码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="htbm">
              <a-input v-model="model.htbm" placeholder="请输入合同编码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="交易流水号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="jylsh">
              <a-input v-model="model.jylsh" placeholder="请输入交易流水号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="资产负债类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="fzlx">
              <j-tree-select
                ref="treeSelect"
                placeholder="请选择资产负债类型"
                v-model="model.fzlx"
                dict="llbb_param_config,name,code"
                pidValue="41861CBDBEA841008FDD6D4290E5CB9F"
                hasChildField="has_child"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="产品类别" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="cplb">
              <j-tree-select
                ref="treeSelect"
                placeholder="请选择产品类别"
                v-model="model.cplb"
                dict="llbb_param_config,name,code"
                pidValue="2BAE266DB1EC4CB2A31066753EFE224E"
                hasChildField="has_child"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="合同起始日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="htqsrq">
              <j-date placeholder="请选择合同起始日期" v-model="model.htqsrq"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="合同到期日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="htdqrq">
              <j-date placeholder="请选择合同到期日期" v-model="model.htdqrq"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="合同实际终止日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="htsjzzrq">
              <j-date placeholder="请选择合同实际终止日期" v-model="model.htsjzzrq"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="币种" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bz">
              <j-tree-select
                ref="treeSelect"
                placeholder="请选择币种"
                v-model="model.bz"
                dict="jrsj_bz_config,name,code"
                pidValue="1382973175608823809"
                hasChildField="has_child"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="发生金额" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="fsje">
              <a-input-number v-model="model.fsje" placeholder="请输入发生金额" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="发生金额折人民币" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="fsjezrmb">
              <a-input-number v-model="model.fsjezrmb" placeholder="请输入发生金额折人民币" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="利率是否固定" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="llsfgd">
              <j-tree-select
                ref="treeSelect"
                placeholder="请选择利率是否固定"
                v-model="model.llsfgd"
                dict="llbb_param_config,name,code"
                pidValue="1f530e35f5b243449bb010a82a59b059"
                hasChildField="has_child"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="利率水平" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="llsp">
              <a-input-number v-model="model.llsp" placeholder="请输入利率水平" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="定价基准类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="djjzlx">
              <j-tree-select
                ref="treeSelect"
                placeholder="请选择定价基准类型"
                v-model="model.djjzlx"
                dict="llbb_param_config,name,code"
                pidValue="1382971691022340098"
                hasChildField="has_child"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="基准利率" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="jzll">
              <a-input-number v-model="model.jzll" placeholder="请输入基准利率" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="计息方式" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="jxfs">
              <j-tree-select
                ref="treeSelect"
                placeholder="请选择计息方式"
                v-model="model.jxfs"
                dict="llbb_param_config,name,code"
                pidValue="1491316094420959234"
                hasChildField="has_child"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="发生/结清标识" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="fsjqbz">
              <j-tree-select
                ref="treeSelect"
                placeholder="请选择发生/结清标识"
                v-model="model.fsjqbz"
                dict="llbb_param_config,name,code"
                pidValue="1eaf36ab8bbc462fae31c8abe550f6cf"
                hasChildField="has_child"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="交易对手母公司代码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="jydsmgsdm">
              <a-input v-model="model.jydsmgsdm" placeholder="请输入交易对手母公司代码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="交易对手母公司名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="jydsmgsmc">
              <a-input v-model="model.jydsmgsmc" placeholder="请输入交易对手母公司名称"  ></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'JsCdAmtBankLendForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 7 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/jsCdAmtBankLend/jsCdAmtBankLend/add",
          edit: "/jsCdAmtBankLend/jsCdAmtBankLend/edit",
          queryById: "/jsCdAmtBankLend/jsCdAmtBankLend/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.guid){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }

        })
      },
    }
  }
</script>
